import { _decorator, Animation, Component, ERigidBody2DType, Node, tween, v3, Vec3 } from 'cc';
import { Item } from '../Item';
import { MigaManager } from '../MigaManager';
const { ccclass, property } = _decorator;

@ccclass('Basket')
export class Basket extends Component {

    @property(Node)
    point: Node;

    @property(Animation)
    ani: Animation;

    start() {

    }

    update(deltaTime: number) {

    }

    Dunk(item: Item) {
        if (item.size > 1) return;
        item.rig.type = ERigidBody2DType.Animated;
        item.collider.enabled = false;
        item.node.setParent(this.point, true);
        tween(item.node)
            .to(0.5, { position: Vec3.ZERO })
            .call(() => {
                this.ani.play();
            })
            .by(0.5, { position: v3(0, -400) })
            .call(() => {
                item.isTween = false;
                item.rig.type = ERigidBody2DType.Dynamic;
                item.collider.enabled = true;
                item.node.setParent(MigaManager.Instance.touchPanel, true);
            })
            .start();
    }
}


